/**
 * Created by Administrator on 2019/5/20/020.
 */
import CZML_GENERALTOOLS_CLASS from "./../main/CZML_GENERALTOOLS_CLASS.js"
// 添加地表运动物体（包括船、车辆等）经纬高
// id：ID（显示除轨道外的其他数据），服务化平台给出的UUID，字符串
// name：地表运动物体名称，字符串
// OrbitStartTime：轨迹开始时间 字符串 输入格式为UTCG
// OrbitEndTime：轨道结束时间，字符串，输入格式为UTCG
// position：地表运动物体位置，数组：[相对秒1,经，纬，高,相对秒2,经，纬，高]([0,30,30,30,5,30,30,30])
// orientation：地表运动物体姿态，数组：[相对秒1,q1,q2,q3,q0]([0,0,0,0,1])，q0为标量  时间减去开始时间
// ModelVisible：三维模型是否可见（true/false）
// Model3DPath：三维模型路径，字符串
// ModelSize：三维模型大小，数值（1000）
// MarkerVisible：二维标签是否可见（true/false）
// MarkerPath：二维标签图片路径，字符串
// MaekerPixelSize：二维标签图片大小（1）
// MarkerColor：二维标签颜色，数组：[R,G,B,255]（[255,0,0,255]）
// MarkerXOriginPos：二维标签水平对齐，字符串，三种可选（"CENTER"，"LEFT"，"RIGHT"）
// MarkerYOriginPos：二维标签垂直对齐，字符串，三种可选（"CENTER"，"LEFT"，"RIGHT"）
// OrbitVisible：轨迹是否可见（true/false）
// OrbitLineStyle：轨迹风格，0代表直线，1代表虚线
// OrbitLineWidth：轨迹宽度，数值（4）
// OrbitColor：轨迹颜色，数组：[R,G,B,255]（[255,0,0,255]）
// Distance:二三维图标切换的距离，数值(5.5e6)
// return：<Boolean> 新添加id时返回true，替换存在id时返回false
class CZML_SurfaceMovingObject {
    constructor(viewer, id, name, OrbitStartTime, OrbitEndTime, position, orientation, ModelVisible, Model3DPath, ModelSize,
                MarkerVisible, MarkerPath, MaekerPixelSize, MarkerColor, MarkerXOriginPos, MarkerYOriginPos,
                OrbitVisible, OrbitLineStyle, OrbitLineWidth, OrbitColor, Distance) {
        this._viewer = viewer
        this.id = id
        this.name = name
        this.OrbitStartTime = OrbitStartTime
        this.OrbitEndTime = OrbitEndTime
        this.position = position
        this.orientation = orientation
        this.ModelVisible = ModelVisible
        this.Model3DPath = Model3DPath
        this.ModelSize = ModelSize
        this.MarkerVisible = MarkerVisible
        this.MarkerPath = MarkerPath
        this.MaekerPixelSize = MaekerPixelSize
        this.MarkerColor = MarkerColor
        this.MarkerXOriginPos = MarkerXOriginPos
        this.MarkerYOriginPos = MarkerYOriginPos
        this.OrbitVisible = OrbitVisible
        this.OrbitLineStyle = OrbitLineStyle
        this.OrbitLineWidth = OrbitLineWidth
        this.OrbitColor = OrbitColor
        this.Distance = Distance
        this.CZML_AddSurfaceMovingObject()
    }

    CZML_AddSurfaceMovingObject() {
        const sOrbitStartTime = CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.OrbitStartTime)
        const sOrbitEndTime = CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.OrbitEndTime)
        const AvailabilityTime = sOrbitStartTime + "/" + sOrbitEndTime
        const GroundVehicle = {
            id: this.id,
            availability: AvailabilityTime,
            name: this.name,
            billboard: {
                eyeOffset: {
                    cartesian: [
                        0, 0, 0
                    ]
                },
                horizontalOrigin: this.MarkerXOriginPos,
                image: this.MarkerPath,
                pixelOffset: {
                    cartesian2: [
                        0, 0
                    ]
                },
                scale: this.MaekerPixelSize,
                show: this.MarkerVisible,
                distanceDisplayCondition: {
                    distanceDisplayCondition: [this.Distance]
                },
                verticalOrigin: this.MarkerYOriginPos
            },
            label: {
                fillColor: {
                    rgba: this.MarkerColor
                },
                font: "11pt Lucida Console",
                horizontalOrigin: "LEFT",
                pixelOffset: {
                    cartesian2: [
                        10, 0
                    ]
                },
                show: this.MarkerVisible,
                style: "FILL_AND_OUTLINE",
                text: this.name,
                verticalOrigin: "CENTER"
            },
            path: {
                show: [
                    {
                        interval: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
                        boolean: this.OrbitVisible
                    }
                ],
                width: this.OrbitLineWidth,
                material: CZML_GENERALTOOLS_CLASS.GetMaterialObject(this.OrbitLineStyle, this.OrbitColor),
                resolution: 120
            },
            model: {
                gltf: this.Model3DPath,
                scale: this.ModelSize,
                distanceDisplayCondition: {
                    distanceDisplayCondition: [0, this.Distance]
                },
                show: this.ModelVisible,
                runAnimations: false
            },
            position: {
                interpolationAlgorithm: "LAGRANGE",
                interpolationDegree: 5,
                epoch: sOrbitStartTime,
                cartographicDegrees: this.position
            },
            orientation: {
                interpolationAlgorithm: "LAGRANGE",
                interpolationDegree: 2,
                epoch: sOrbitStartTime,
                unitQuaternion: this.orientation
            }
        }
        // 插入该数据对象
        const ret = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.id, GroundVehicle, true)
        // 上图
        CZML_GENERALTOOLS_CLASS.Upper(this._viewer)
        return ret
    }
}
export default CZML_SurfaceMovingObject
